<?php
/*
 * @Author: your name2
 * @Date: 2021-09-21 16:46:35
 * @LastEditTime: 2022-03-02 21:56:12
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /nlog/app/Http/Controllers/AdminController/Login.php
 */

namespace App\Http\Controllers\crm;


use Illuminate\Support\Facades\Request;
// use App\Models\crm_model\CrmCustomer as CrmCustomerDb;                        // admins表
use App\Models\crm_model\CrmSituation as CrmSituationDb;

class CrmSituation extends BaseController
{

    // public function customerAdd()
    // {
    //     return    redis_mysql_add('crm_customer');
    // }

    // public function customerEdit()
    // {
    //     return    redis_mysql_edit('crm_customer');
    // }


    // public function customerSelOne()
    // {
    //     return    redis_mysql_selone('crm_customer');
    // }

    // public function customerList()
    // {
    //     // if(Request::has('division_id')){
    //         $whereStr = '';
    //         $limitStr = '';
    //         $division_id =  Request::has('division_id')? Request::input('division_id'):$this->getAdminInfo()['division_id'];
    //         if (Request::input('pageSize') && Request::input('page')) {
    //             $limitStr =   limit_joint(Request::input('page'), Request::input('pageSize'));
    //         }
    //         if(Request::has('keyWord')){

    //         $keyWord = array_filter(Request::input('keyWord'), 'filtrfunction');
    //         if(isset($keyWord['manyField'])){
    //             $whereStr .= havaWhereLikeManyField($keyWord['manyField']);
    //             unset($keyWord['manyField']);
    //         }
    //         if (!empty($keyWord)) {
    //             $whereStr .= havaWhereLikeJoinEqual($keyWord);
    //         }
    //     }


    //         $list  =  CrmCustomerDb::crmCustomerList( $division_id ,$whereStr, $limitStr);
    //         $count =  CrmCustomerDb::crmCustomerCount($division_id ,$whereStr);
    //         return $this->create(200,'查询成功',['list'=>$list,'total'=>$count[0]['count']]);
    //     // }


    // }

    public function situationUpdateAdd()
    {
        if (Request::has('formData')) {
            $formData = Request::input('formData');
            if (isset($formData['id']) && $formData['id']) {
                $id = $formData['id'];
                unset($formData['id']);
                $formData['update_time'] = date('Y-m-d H:i:s');
                $res = CrmSituationDb::situationUpdate($formData, $id);
            } else {
                $formData['create_time'] = date('Y-m-d H:i:s');
                $res = CrmSituationDb::situationInsert($formData);
                $situation_id = $res;
            }
            if ($res) {
                return   isset($situation_id) ? $this->create(200, '保存成功', ['id' => $situation_id]) : $this->create(200, '保存成功');
            } else {
                return   $this->create(100, '保存失败');
            }
        }
    }

    public function situationList()
    {
        // if(Request::has('division_id')){
        $whereStr = '';
        $limitStr = '';
        if (Request::input('pageSize') && Request::input('page')) {
            $limitStr =   limit_joint(Request::input('page'), Request::input('pageSize'));
        }
        if (Request::has('keyWord')) {

            $keyWord = array_filter(Request::input('keyWord'), 'filtrfunction');
            if (isset($keyWord['manyField'])) {
                $whereStr .= havaWhereLikeManyField($keyWord['manyField']);
                unset($keyWord['manyField']);
            }
            if (!empty($keyWord)) {
                $whereStr .= havaWhereLikeJoinEqual($keyWord);
            }
        }


        $list  =  CrmSituationDb::list($whereStr, $limitStr);
        $count =  CrmSituationDb::count($whereStr);
        return $this->create(200, '查询成功', ['list' => $list, 'total' => $count[0]['count']]);
        // }


    }

    // public function 

}
